<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>长度最小的子数组</title>
</head>
<body>
  <script>
var minSubArrayLen = function (target, nums) {
    let res; //返回值
    let i = 0, j = 0; //双指针
    let sum = 0;
     console.log(res);
    for (; j < nums.length; j++) {
        sum += nums[j];
        while (sum >= target) {
            res = res < j - i + 1 ? res : j - i + 1;
            
            sum -= nums[i];
            console.log(sum);
            i++;
        }
    }
    return res ? res : 0;
};
console.log(minSubArrayLen(7,[2,3,1,2,4,3]));
  </script>
</body>
</html>